home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / KinoExpert (RU).ifs < prev    next >
Encoding:
Text File  |  2004-10-26  |  10.6 KB  |  347 lines

  1. // GETINFO SCRIPTING
  2. // Imports russian movies info from KinoExpert
  3.  
  4. (***************************************************
  5.  *  Movie information import script for:           *
  6.  *    KinoExpert Russian,                          *
  7.  *    http://www.kinoexpert.ru/                    *
  8.  *                                                 *
  9.  *  (c) 2004 Serguei Tarassov                      *
  10.  *  http://www.arbinada.com                        *
  11.  *                                                 *
  12.  *  Last update:                                   *
  13.  *  - 24.10.2004                                   *
  14.  *                                                 *
  15.  *  Known issues:                                  *
  16.  *  - none                                         *
  17.  *                                                 *
  18.  *  For use with Ant Movie Catalog 3.4.0           *
  19.  *  www.antp.be/software/moviecatalog              *
  20.  *                                                 *
  21.  *  This program is free software; you can         *
  22.  *  redistribute it and/or modify it under the     *
  23.  *  terms of the GNU General Public License as     *
  24.  *  published by the Free Software Foundation;     *
  25.  *  either version 2 of the License, or (at your   *
  26.  *  option) any later version.                     *
  27.  ***************************************************)
  28.  
  29. program KinoExpert;
  30. const
  31.   DEBUG_MODE = false;
  32.   DEBUG_FOUND_FILMS_FILENAME = 'KinoExpert_found_results.htm';
  33.   DEBUG_FILM_FILENAME        = 'KinoExpert_film.htm';
  34.   BaseAddress = 'http://www.kinoexpert.ru/';
  35.  
  36. var
  37.   MovieName: string;
  38.  
  39. { Some utils functions }
  40. procedure DebugOutput(Value: string);
  41. begin
  42.   if DEBUG_MODE then
  43.     Input('Watch', 'Value', Value);
  44. end;
  45.  
  46. procedure DebugOutputFile(FileName: string; FileText: string);
  47. var
  48.   Log: TStringList;
  49. begin
  50.   if DEBUG_MODE then begin
  51.     Log := TStringList.Create;
  52.     Log.Text := FileText;
  53.     Log.SaveToFile(FileName);
  54.     Log.Free;
  55.   end;
  56. end;
  57.  
  58. procedure ClearString(var Value: string);
  59. begin
  60.   HTMLRemoveTags(Value);
  61.   HTMLDecode(Value);
  62.   Value := StringReplace(Value, #13, '');
  63.   Value := StringReplace(Value, #10, '');
  64.   Value := trim(Value);
  65. end;
  66.  
  67. procedure ClearText(var Value: string);
  68. var
  69.   s: string;
  70. begin
  71.   if length(Value) < 2 then exit;
  72.   Value := trim(Value);
  73.   s := copy(Value, 2, length(Value));
  74.   s := StringReplace(s, '<br>', #13#10);
  75.   s := StringReplace(s, '<BR>', #13#10);
  76.   s := StringReplace(s, '<p>', #13#10#13#10);
  77.   s := StringReplace(s, '<p>', #13#10#13#10);
  78.   Value := copy(Value, 1, 1) + s;
  79.   HTMLRemoveTags(Value);
  80.   HTMLDecode(Value);
  81.   Value := trim(Value);
  82. end;
  83.  
  84. procedure RemoveLastDot(var Value: string);
  85. begin
  86.   if length(Value) > 1 then
  87.     if copy(Value, length(Value), 1) = '.' then begin
  88.       Value := copy(Value, 1, length(Value) - 1);
  89.     end;
  90. end;
  91.  
  92.  
  93.  
  94. { Pages parsing }
  95.  
  96. const
  97.   FoundLabel = '<br>╧ε Γα°σ∞≤ τα∩≡ε±≤ φαΘΣσφε';
  98.   FoundMovieTitleRef = 'index.asp?comm=4&';
  99.   FoundMovieYearLabel = '<td';
  100.  
  101. procedure AnalyzeFoundFilmsPage(URL: string);
  102. var
  103.   Page: TStringList;
  104.     FoundTable: string;
  105.     pos1, pos2: integer;
  106. begin
  107.   Page := TStringList.Create;
  108.   Page.Text := GetPage(URL);
  109.   DebugOutputFile(DEBUG_FOUND_FILMS_FILENAME, Page.Text);
  110.   pos1 := pos(FoundLabel, Page.Text);
  111.   if pos1 <> 0 then begin
  112.     FoundTable := copy(Page.Text, Pos1, length(Page.Text));
  113.     FoundTable := copy(FoundTable, pos('<table', FoundTable), length(FoundTable));
  114.     FoundTable := copy(FoundTable, 1, pos('</table', FoundTable) + 7);
  115.     //DebugOutput(FoundTable);
  116.     if pos(FoundMovieTitleRef, FoundTable) > 0 then
  117.       AddFoundMoviesTitles(FoundTable);
  118.   end;
  119.   Page.Free;
  120. end;
  121.  
  122.  
  123. procedure AddFoundMoviesTitles(Table: string);
  124. var
  125.     CurName, CurURL, SelectedURL, s: string;
  126.     pos2, len: integer;
  127. begin
  128.   PickTreeClear;
  129.      PickTreeAdd('Movies', '');
  130.   len := length(Table);
  131.   while pos(FoundMovieTitleRef, Table) > 0 do begin
  132.     Table := copy(Table, pos(FoundMovieTitleRef, Table), len);
  133.     pos2 := pos('"', Table);
  134.     CurURL := copy(Table, 1, pos2 - 1);
  135.     //DebugOutput(CurURL);
  136.     Table := copy(Table, pos('>', Table) + 1, len);
  137.     pos2 := pos('<', Table);
  138.     CurName := copy(Table, 1, pos2 - 1);
  139.     ClearString(CurName);
  140.     Table := copy(Table, pos2 + 1, len);
  141.     Table := copy(Table, pos(FoundMovieYearLabel, Table) + 1, len);
  142.     Table := copy(Table, pos('>', Table) + 1, len);
  143.     pos2 := pos('<', Table);
  144.     s := copy(Table, 1, pos2 - 1);
  145.     ClearString(s);
  146.     CurName := CurName + ' ' + s;
  147.     Table := copy(Table, pos2 + 1, len);
  148.     //DebugOutput(CurName);
  149.     PickTreeAdd(CurName, BaseAddress + CurURL);
  150.   end;
  151.   
  152.     if PickTreeExec(SelectedURL) then
  153.     AnalyzeFilmPage(SelectedURL);
  154. end;
  155.  
  156.  
  157. const
  158.   FilmTitleAnchor1 = '∩εΩατα≥ⁿ Γ±σ⌡ αΩ≥σ≡εΓ';
  159.   FilmTitleAnchor2 = '╚±Ωα≥ⁿ ∩ε ⌠ε≥ε';
  160.   FilmCountryAnchor = '<b';
  161.   FilmMainTableAnchor = '─δΦ≥.';
  162.   FilmActorsAnchor = '┬ ≡εδ ⌡';
  163.   FilmDirectorAnchor = '╨σµΦ±±σ≡';
  164.   FilmProducerAnchor = '╧≡εΣ■±σ≡';
  165.   FilmAwardsAnchor = '═απ≡αΣ√ Φ ∩≡Φ∞σ≈αφΦ ';
  166.   FilmContentAnchor = '╩≡α≥Ωεσ ±εΣσ≡µαφΦσ';
  167.   FilmImageRefAnchor = '"javascript:window.open(''fotorate.asp?img=';
  168.  
  169. procedure AnalyzeFilmPage(SelectedURL: string);
  170. var
  171.   Page: TStringList;
  172.     Content, Value, ImageURL: string;
  173.     pos1, pos2, len: integer;
  174. begin
  175.   Page := TStringList.Create;
  176.   Page.Text := GetPage(SelectedURL);
  177.   DebugOutputFile(DEBUG_FILM_FILENAME, Page.Text);
  178.   
  179.   SetField(fieldURL, SelectedURL)
  180.  
  181.   len := length(Page.Text);
  182.   
  183.   // Film title
  184.   pos1 := pos(FilmTitleAnchor1, Page.Text);
  185.   if pos1 = 0 then
  186.     pos1 := pos(FilmTitleAnchor2, Page.Text);
  187.   Content := copy(Page.Text, pos1, len);
  188.   Content := copy(Content, pos('>', Content) + 1, len);
  189.   pos2 := pos('</font', Content);
  190.   Value := copy(Content, 1, pos2 - 1);
  191.   ClearString(Value);
  192.   SetField(fieldOriginalTitle, Value)
  193.   SetField(fieldTranslatedTitle, Value)
  194.   //DebugOutput(Value);
  195.   Content := copy(Content, pos2, len);
  196.  
  197.   // Country
  198.   pos2 := pos(FilmCountryAnchor, Content);
  199.   if pos2 > 0 then begin
  200.     Content := copy(Content, pos2, len);
  201.     pos2 := pos('</', Content);
  202.     Value := copy(Content, 1, pos2 - 1);
  203.     ClearString(Value);
  204.     SetField(fieldCountry, Value)
  205.     Content := copy(Content, pos2, len);
  206.   end;
  207.  
  208.   //
  209.   // Film main attributes (small table on top)
  210.   //
  211.   Content := copy(Content, pos(FilmMainTableAnchor, Content), len);
  212.   Content := copy(Content, pos('<td', Content), len);
  213.   Content := copy(Content, pos('>', Content) + 1, len);
  214.   //DebugOutput(Content);
  215.   // Studio
  216.   pos2 := pos('<td', Content);
  217.   Value := copy(Content, 1, pos2 - 1);
  218.   ClearString(Value);
  219.   SetField(fieldSource, Value);
  220.   Content := copy(Content, pos2, len);
  221.   Content := copy(Content, pos('>', Content) + 1, len);
  222.   // Year
  223.   pos2 := pos('<td', Content);
  224.   Value := copy(Content, 1, pos2 - 1);
  225.   ClearString(Value);
  226.   SetField(fieldYear, Value);
  227.   Content := copy(Content, pos2, len);
  228.   Content := copy(Content, pos('>', Content) + 1, len);
  229.   // Category
  230.   pos2 := pos('<td', Content);
  231.   Value := copy(Content, 1, pos2 - 1);
  232.   ClearString(Value);
  233.   SetField(fieldCategory, Value);
  234.   Content := copy(Content, pos2, len);
  235.   Content := copy(Content, pos('>', Content) + 1, len);
  236.   // Length
  237.   pos2 := pos('</td', Content);
  238.   Value := copy(Content, 1, pos2 - 1);
  239.   ClearString(Value);
  240.   SetField(fieldLength, Value);
  241.   Content := copy(Content, pos2, len);
  242.   Content := copy(Content, pos('>', Content) + 1, len);
  243.   
  244.   
  245.   //
  246.   // Other attributes
  247.   //
  248.   // Actors
  249.   pos2 := pos(FilmActorsAnchor, Content);
  250.   if pos2 > 0 then begin
  251.     Content := copy(Content, pos2, len);
  252.     Content := copy(Content, pos('>', Content) + 1, len);
  253.     //DebugOutput(Content);
  254.     pos2 := pos(FilmDirectorAnchor, Content);
  255.     Value := copy(Content, 1, pos2 - 1);
  256.     ClearText(Value);
  257.     SetField(fieldActors, Value);
  258.     Content := copy(Content, pos2, len);
  259.   end;
  260.  
  261.   // Director
  262.   pos2 := pos(FilmDirectorAnchor, Content);
  263.   if pos2 > 0 then begin
  264.     Content := copy(Content, pos2, len);
  265.     Content := copy(Content, pos('>', Content) + 1, len);
  266.     pos2 := pos('<br>', Content);
  267.     Value := copy(Content, 1, pos2 - 1);
  268.     ClearString(Value);
  269.     RemoveLastDot(Value);
  270.     SetField(fieldDirector, Value);
  271.     Content := copy(Content, pos2, len);
  272.   end;
  273.   
  274.   // Producer
  275.   pos2 := pos(FilmProducerAnchor, Content);
  276.   if pos2 > 0 then begin
  277.     Content := copy(Content, pos2, len);
  278.     Content := copy(Content, pos('>', Content) + 1, len);
  279.     pos2 := pos('<br>', Content);
  280.     Value := copy(Content, 1, pos2 - 1);
  281.     ClearString(Value);
  282.     RemoveLastDot(Value);
  283.     SetField(fieldProducer, Value);
  284.     Content := copy(Content, pos2, len);
  285.   end;
  286.   
  287.   // Awards
  288.   pos2 := pos(FilmAwardsAnchor, Content);
  289.   if pos2 > 0 then begin
  290.     Content := copy(Content, pos2, len);
  291.     Content := copy(Content, pos('>', Content) + 1, len);
  292.     pos2 := pos('</div', Content);
  293.     Value := copy(Content, 1, pos2 - 1);
  294.     ClearText(Value);
  295.     SetField(fieldComments, Value);
  296.     Content := copy(Content, pos2, len);
  297.   end;
  298.  
  299.   // Content
  300.   pos2 := pos(FilmContentAnchor, Content);
  301.   if pos2 > 0 then begin
  302.     Content := copy(Content, pos2, len);
  303.     Content := copy(Content, pos('>', Content) + 1, len);
  304.     pos2 := pos('</div', Content);
  305.     Value := copy(Content, 1, pos2 - 1);
  306.     ClearText(Value);
  307.     SetField(fieldDescription, Value);
  308.     Content := copy(Content, pos2, len);
  309.   end;
  310.   
  311.   // image
  312.   pos2 := pos(FilmImageRefAnchor, Content);
  313.   if pos2 > 0 then begin
  314.     Content := copy(Content, pos2, len);
  315.     ImageURL := copy(Content, pos('''', Content) + 1, len);
  316.     pos2 := pos('''', ImageURL);
  317.     Content := copy(Content, pos2, len);
  318.     ImageURL := copy(ImageURL, 1, pos2 - 1);
  319.     ImageURL := BaseAddress + StringReplace(ImageURL, 'fotorate.asp?img=', 'foto/');
  320.     if Input('═αΘΣσφα Ωα≡≥ΦφΩα Ω ⌠Φδⁿ∞≤', '╟απ≡≤τΦ≥ⁿ Ωα≡≥ΦφΩ≤ ?'#13#10'URL:', ImageURL) then
  321.       GetPicture(ImageURL, False); // False = do not store picture externally
  322.   end;
  323.  
  324.  
  325.   Page.Free;
  326.   
  327.   DisplayResults;
  328. end;
  329.  
  330. begin
  331.   if CheckVersion(3,4,0) then
  332.   begin
  333.     MovieName := GetField(fieldOriginalTitle);
  334.     if MovieName = '' then
  335.       MovieName := GetField(fieldTranslatedTitle);
  336.     if Input('Import from KinoExpert',
  337.              'Enter the title of the movie:', MovieName) then
  338.     begin
  339.       AnalyzeFoundFilmsPage(BaseAddress + 'index.asp?comm=1&kw=' +
  340.                   UrlEncode(MovieName) + '&fop=false&pack=0#1');
  341. //      AnalyzePage('http://localhost/search1.htm');
  342.     end;
  343.   end else
  344.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  345. end.
  346.  
  347.